package com.mall.server.controller.sms;

import com.mall.model.domain.SmsHomeRecommendSubject;
import com.mall.model.vo.CommonPage;
import com.mall.model.vo.CommonResult;
import com.mall.server.service.sms.SmsHomeRecommendSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/home/recommendSubject")
public class SmsHomeRecommendSubjectController {

    @Autowired
    private SmsHomeRecommendSubjectService smsHomeRecommendSubjectService;

    /**
     * 分页查询推荐
     */
    @GetMapping("/list")
    public CommonResult list(@RequestParam(defaultValue = "1") Integer pageNum
            , @RequestParam(defaultValue = "10") Integer pageSize
            , SmsHomeRecommendSubject subject) {

        CommonPage cp = smsHomeRecommendSubjectService.list(pageNum, pageSize, subject);

        return CommonResult.success(cp);
    }

    /**
     * 添加首页推荐专题
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody List<SmsHomeRecommendSubject> homeRecommendSubjectList) {

        smsHomeRecommendSubjectService.create(homeRecommendSubjectList);

        return CommonResult.success(null);
    }

    /**
     * 批量删除推荐
     */
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam("ids") List<Long> ids) {

        smsHomeRecommendSubjectService.delete(ids);

        return CommonResult.success(null);
    }

    /**
     * 批量修改推荐状态
     */
    @PostMapping("/update/recommendStatus")
    public CommonResult update(@RequestParam("ids") List<Long> ids,
                               SmsHomeRecommendSubject subject) {

        smsHomeRecommendSubjectService.update(ids, subject);

        return CommonResult.success(null);
    }


    /**
     * 修改推荐排序
     */
    @PostMapping("/update/sort/{id}")
    public CommonResult updateSort(@PathVariable Integer id,
                                   SmsHomeRecommendSubject subject) {

        smsHomeRecommendSubjectService.updateSort(id, subject);

        return CommonResult.success(null);
    }


}
